package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cedarsoftware.util.io.JsonWriter;

import dao.DaoUser;
import user.User;


public class S_Login extends HttpServlet {
	private static final long serialVersionUID = 1L;


	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("html");
		DaoUser dao = new DaoUser();
		User user = dao.login(request.getParameter("mail"), request.getParameter("password"));
		if(user != null) {
			request.getSession().setAttribute("user", user);
		}
		else {
			response.setStatus(599);
		}
	}
}